package com.pagepub.core.tag.validator;

import javax.servlet.jsp.JspException;
import javax.servlet.jsp.tagext.TagSupport;

public class FormValidateBasic extends TagSupport {

	private static final long serialVersionUID = -8924746731117139224L;

	protected String wordcolor;

	protected String wrongimage;

	/**
	 * @param args
	 */

	@Override
	public int doStartTag() throws JspException {
		// TODO 自动生成方法存根

		return 1;
	}

	/**
	 * 判断1个字符数字
	 * 
	 * 
	 */

	public StringBuffer IsDigit() {
		StringBuffer string = new StringBuffer();
		string.append("<script language=\"javascript\">");
		string.append("function IsDigit(cCheck) ");
		string.append("	{ ");
		string.append("		return (('0'<=cCheck) && (cCheck<='9')); ");
		string.append("	} ");
		string.append("</script>");
		return string;
	}

	/**
	 * 判断是否为字母
	 * 
	 * 
	 */
	public StringBuffer IsAlpha() {
		StringBuffer string = new StringBuffer();
		string.append("<script language=\"javascript\">");
		string.append("	function IsAlpha(cCheck) ");
		string.append("	{ ");
		string
				.append("		return ((('a'<=cCheck) && (cCheck<='z')) || (('A'<=cCheck) && (cCheck<='Z')));");
		string.append("	} ");
		string.append("</script>");
		return string;
	}

	/**
	 * 去除空格
	 * 
	 */
	public StringBuffer cTrim() {
		StringBuffer string = new StringBuffer();
		string.append("<script language=\"javascript\">");
		string.append("function cTrim(sInputString,iType)");
		string.append("{");
		string.append("		sInputString=\"\"+sInputString;");
		string.append("	var sTmpStr=' ';");
		string.append("		var i=-1;");
		string.append("	if(iType==0||iType==1)");
		string.append("		{");
		string.append("			while(sTmpStr==' ')");
		string.append("		{");
		string.append("			++i;");
		string.append("			sTmpStr=sInputString.substr(i,1);");
		string.append("		}");
		string.append("		sInputString=sInputString.substring(i);");
		string.append("	}");

		string.append("	if(iType==0 || iType==2)");
		string.append("	{");
		string.append("		sTmpStr=' ';");
		string.append("	i=sInputString.length;");
		string.append("	while(sTmpStr==' ')");
		string.append("	{");
		string.append("		--i;");
		string.append("		sTmpStr=sInputString.substr(i,1);");
		string.append("	}");
		string.append("	sInputString=sInputString.substring(0,i+1);");
		string.append("}");
		string.append("	return sInputString;");
		string.append("	}");
		string.append("</script>");
		return string;
	}

	/**
	 * 调用span显示相应的内容
	 * 
	 */
	public StringBuffer display() {
		StringBuffer string = new StringBuffer();
		string
				.append("document.getElementById(spanname).innerHTML=imgurl+\"<font color=\\\""
						+ wordcolor + "\\\">\"+message+\"</font>\";");
		return string;

	}

	public StringBuffer displayrightmessage() {
		StringBuffer string = new StringBuffer();
		string
				.append("document.getElementById(spanname).innerHTML=imgurl+\"<font color=\\\""
						+ wordcolor + "\\\">\"+message+\"</font>\";");
		return string;

	}

	/**
	 * 至span为空
	 * 
	 */
	public StringBuffer displayempty() {
		StringBuffer string = new StringBuffer();
		string.append("document.getElementById(spanname).innerHTML=\"\";");
		return string;
	}

	/**
	 * 判断字符串是否为数字
	 * 
	 */
	public StringBuffer checknum() {
		StringBuffer string = new StringBuffer();
		string.append("<script language=\"javascript\">");
		string.append("function checkeNum(str){");
		string.append("		var num=\"0123456789\";");
		string.append("		for(i=0;i<str.length;i++){");
		string.append("		   c=str.charAt(i);");
		string.append("			if(num.indexOf(c)==-1) ");
		string.append("			return true;");
		string.append("		}");
		string.append("		return false;");
		string.append("	}");
		string.append("</script>");
		return string;
	}

	/**
	 * 检测邮箱格式 格式正确时返回false
	 * 
	 * 
	 */
	public StringBuffer checkemailformat() {
		StringBuffer string = new StringBuffer();
		string.append("<script language=\"javascript\">");
		string.append("function Checkemailformat(emailstr)");
		string.append("	{");
		string
				.append("	     var reg=/^[\\w-]+(\\.[\\w-]+)*@[\\w-]+(\\.[\\w-]+)+$/;");
		string.append("	     var regexp = new RegExp(reg);");
		string.append("	     if(!regexp.test(emailstr))");
		string.append("		{");
		string.append("	   return true;");
		string.append("		}");
		string.append("		else");
		string.append("		{");
		string.append("		   return false;");
		string.append("		}");

		string.append("	}");
		string.append("</script>");
		return string;
	}

	public String dealwithstr(String str) {
		return str.subSequence(0, str.lastIndexOf(")")).toString();

	}

	public String getWordcolor() {
		return wordcolor;
	}

	public void setWordcolor(String wordcolor) {
		this.wordcolor = wordcolor;
	}

	public String getWrongimage() {
		return wrongimage;
	}

	public void setWrongimage(String wrongimage) {
		this.wrongimage = wrongimage;
	}
}
